<template>
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div></div>
      </div>
      <tree :treeData="treeData" :checkData="checkData" name="currencyList" nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick" :defaultProps="defaultProps">
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 表格 -->
      <div class="warningObject_table">
        <div class="perpsonObject">
          <div class="mechanism_nav">
            <!-- 左侧 -->
            <div class="mechanism_nav_left">
              <input type="text" placeholder="姓名/手机" v-model="getList.keyWord" />
              <el-button type="primary" icon="el-icon-search" size="small" @click="yj_searchForm(getList)">查询
              </el-button>
            </div>
            <!-- 顶部按钮 -->
            <div class="print" style="justify-content: flex-end">
              <!-- <el-button type="primary" icon="el-icon-refresh" size="small" @click="yj_searchForm(getList)">
                            </el-button>
                            <el-button type="primary" v-if="yj_view" icon="el-icon-search" size="small"
                                @click="yj_editForm(2)">查看
                            </el-button> -->
              <el-button type="primary" v-if="yj_add" icon="el-icon-search" size="small" @click="yj_editForm(0)">
                新增</el-button>
              <el-button type="primary" v-if="yj_edit" icon="el-icon-edit" size="small" @click="yj_editForm(1)">编辑
              </el-button>
              <el-button type="primary" icon="el-icon-delete" size="small" @click="yj_delForm(fId)">删除
              </el-button>
            </div>
          </div>
          <tableData :config="table_config" :rowKey="rowKey" :dataList="tableData" :loading="listLoading"
            @selection-change="selectionChange" @sort-change="sortChange" @click-change="rowChange" />
          <pagination :info="queryCriteriaData" v-if="navigatepageNums > 1" :treelength="treelength"
            :total="queryCriteriaData.total" :pageNum.sync="getList.page" :limit.sync="getList.pageSize"
            @pagination="yj_searchForm(getList)" />
        </div>
        <div class="departmentObject">
          <div class="mechanism_nav">
            <!-- 左侧 -->
            <div class="mechanism_nav_left"></div>
            <!-- 顶部按钮 -->
            <div class="print" style="justify-content: flex-end">
              <el-button type="primary" icon="el-icon-search" size="small" @click="yj_editObjectForm(0)">
                新增</el-button>
              编辑 <el-button type="primary" icon="el-icon-edit" size="small" @click="yj_editObjectForm(1)">
              </el-button>
              <el-button type="primary" icon="el-icon-delete" size="small"
                @click="yj_delObjectForm(warningObjectformData.fId)">删除
              </el-button>
            </div>
          </div>
          <tableData :config="department_config" :rowKey="rowKey" :dataList="tableObjectData" :loading="listObjectLoading"
            @selection-change="selectionChange" @sort-change="sortChange" @click-change="rowObjectChange" />
        </div>
      </div>
      <!--弹框 查看 -->
      <div class="Control-1 mechanism_dialog">
        <el-dialog :title="editDialog" :modal-append-to-body="false" v-dialogDrag :visible.sync="dialogEditVisible"
          v-loading="loadingEditDialog" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)">
          <div class="dialogBody common" :style="{ height: '550px' }">
            <!-- <div class="baseTitle">基本信息</div> -->
            <div style="height: 100%">
              <el-form :model="formData" :rules="rules" ref="publicForm" class="demo-ruleForm">
                <div class="tableRow">
                  <el-form-item label="姓名" prop="fName" :label-width="formLabelWidth">
                    <el-input v-model="formData.fName" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="是否业主" prop="fIsowner" id="flex-able" :label-width="formLabelWidth">
                    <el-switch v-model="formData.fIsowner" @change="IsownerChange">
                    </el-switch>
                  </el-form-item>
                </div>
                <div class="tableRow">
                  <!-- :label="`${item.fObjectname}/${item.fEqptno}`" -->
                  <el-form-item label="所属对象" prop="fObjects" :label-width="formLabelWidth">
                    <el-select placeholder="请选择" v-model="fEquipmentname" multiple value-key="fId"
                      @change="selectEquipmen">
                      <el-option v-for="(item, index) in ObjectsData" :label="`${item.fObjectname}`" :value="item"
                        :key="index">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </div>

                <div class="tableRow">
                  <el-form-item label="手机号" prop="fTelnumber" :label-width="formLabelWidth">
                    <el-input v-model="formData.fTelnumber" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="编号" prop="fNumber" :label-width="formLabelWidth">
                    <el-input v-model="formData.fNumber" autocomplete="off"></el-input>
                  </el-form-item>
                </div>
                <div class="tableRow">
                  <el-form-item label="性别" prop="fGender" :label-width="formLabelWidth">
                    <el-radio v-model="formData.fGender" label="男">男</el-radio>
                    <el-radio v-model="formData.fGender" label="女">女</el-radio>
                  </el-form-item>
                  <el-form-item label="接受短信" prop="fIsreceivetextmsg" :label-width="formLabelWidth">
                    <el-radio v-model="formData.fIsreceivetextmsg" label="是">是</el-radio>
                    <el-radio v-model="formData.fIsreceivetextmsg" label="否">否</el-radio>
                  </el-form-item>
                </div>

                <div class="tableRow">
                  <el-form-item label="职位" prop="fPosition" :label-width="formLabelWidth">
                    <el-input v-model="formData.fPosition" autocomplete="off"></el-input>
                  </el-form-item>
                  <el-form-item label="学历" prop="fEducation" :label-width="formLabelWidth">
                    <el-input v-model="formData.fEducation" autocomplete="off" placeholder="请输入排序号"></el-input>
                  </el-form-item>
                </div>
              </el-form>
            </div>
          </div>
          <div class="newlyAdded_btn" v-if="submitFlag">
            <el-button type="primary" @click="yj_saveForm('formData')">保存</el-button>
            <el-button type="warning" @click="dialogEditVisible = false">关闭</el-button>
          </div>
        </el-dialog>
      </div>
      <!-- 对象部门 -->
      <div class="Control-1 bansetting" id="smallDialog">
        <el-dialog :title="warningObjectDialog" :modal-append-to-body="false" v-dialogDrag
          :visible.sync="dialogwarningObjectVisible" v-loading="loadingwarningObjectDialog" element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.2)">
          <div class="dialogBody common" :style="{ height: '400px' }">
            <div style="height: 160px">
              <publicForm ref="ObjectForm" lableWidth="60px" :formObj="warningObjectformObj"
                :formData="warningObjectformData" @selectChange="selectObjectChange">
              </publicForm>
            </div>
          </div>
          <div class="newlyAdded_btn" v-if="submitFlag">
            <el-button type="primary" @click="yj_saveObjectForm('formData')">保存</el-button>
            <el-button type="warning" @click="dialogwarningObjectVisible = false">关闭</el-button>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>
<script>
import tree from "@/components/public/common-trees";
import TableData from "@/components/public/el-table";
import elBreadcrumb from "@/components/public/el-breadcrumb.vue";
import publicForm from "@/components/public/el-form.vue";
import {
  getUserCompanyTreeList, //树状图接口
  getNoticeObjectListByCompanyId, //预警通知-对象列表页
  addNoticeObject, // 预警通知-对象新增
  getNoticeObject, // 预警通知-对象详情
  deleteNoticeObject, // 预警通知-对象删除
  getNoticeUserListsByCompanyId, // 预警通知-人员列表页分页
  addNoticeUser, // 预警通知-人员新增
  getNoticeUser, //预警通知-人员详情
  updateNoticeUser, // 【删除】预警通知-人员修改
} from "@/api/request.js";
import { objectType, messageType } from "@/utils/config";
export default {
  name: "Home",
  data() {
    return {
      name: "mixingPlant", //按钮配置页面代号
      yj_add: null, //新增按钮是否显示
      yj_edit: null, //编辑按钮是否显示
      yj_view: null, //查看按钮是否显示
      submitFlag: null, //是否显示保存按钮
      formLabelWidth: "100px",
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {}, //分页
      navigatepageNums1: null, //是否显示分页
      queryCriteriaData1: {}, //分页
      ObjectsData: [],
      fEquipmentname: [], //已选主要仪器设备
      editDialog: null, //dialog的title新增、编辑、查看
      glInfo: null, //骨料详情对象，页面编辑发生改变
      rowKey: "fId", //拌和站树状列表rowKey
      // 对象人员配置项
      listLoading: false, // 对象人员列表数据加载loading
      loadingEditDialog: false, //对象人员 弹框loading
      dialogEditVisible: false, //对象人员 新增弹框是否显示
      table_config: {
        imgKeyWord: "url",
        fileKeyWord: "url",
        fileName: "fFileName",

        dialogHeight: "",
        thead: [
          {
            label: "是否业主",
            prop: "fIsowner",
            minWidth: "70px",
            routerPath: "xxx",
            align: "center",
            filter: true,
            callback: (rowData) => {
              let data = objectType[rowData.fIsowner];
              if (data) {
                return data.label;
              }
            },
          },
          {
            label: "工号",
            prop: "fNumber",
            minWidth: "100px",
            routerPath: "xxx",
            align: "center",
          },
          {
            label: "姓名",
            prop: "fName",
            minWidth: "80px",
            routerPath: "xxx",
            align: "center",
          },
          {
            label: "性别",
            prop: "fGender",
            minWidth: "60px",
            routerPath: "xxx",
            align: "center",
          },

          {
            label: "手机号",
            prop: "fTelnumber",
            minWidth: "150px",
            align: "center",
          },
          {
            label: "接收短信",
            prop: "fIsreceivetextmsg",
            minWidth: "70px",
            routerPath: "xxx",
            align: "center",
          },
          {
            label: "职位",
            prop: "fPosition",
            minWidth: "120px",
            routerPath: "xxx",
          },
          {
            label: "学历",
            prop: "fEducation",
            minWidth: "120px",
            routerPath: "xxx",
          },
        ],
        isCheckBox: false,
        isIndex: true,
        isOperation: true,
      },
      formData: {
        fCompanyid: "", // 施工单位id
        fId: "", // 为null或空字符串时-新增  有值-修改
        fIsowner: false, //是否业主
        fName: "", // 姓名
        fNumber: "", // 编号
        fTelnumber: "", // 电话
        fGender: "男", // 性别
        fIsreceivetextmsg: "是", // 是否接收短信
        fPosition: "", // 职位
        fEducation: "", // 学历
        fObjects: "", // 对象集合
        userName: this.$store.state.userInfo.realName, // 当前登陆人名称
        userId: this.$store.state.userInfo.userId, // 当前登陆人id
      }, //对象人员新增编辑向后台传递对象

      rules: {
        fName: [
          { required: true, message: "请输入姓名", trigger: "blur" },
          // { min: 1, max: 25, message: "最多输入25个文本", trigger: "blur" },
        ],
        fTelnumber: [
          { required: true, message: "请输入手机号码", trigger: "blur" },
          {
            required: true,
            pattern: /^1[3456789]\d{9}$/,
            message: "手机号格式不正确",
            trigger: "blur",
          },
        ],
        // fNature: [
        //     { required: true, message: "请选择机构性质", trigger: "change" },
        // ],
      },

      // 部门
      warningObjectDialog: null, // 部门 title新增、编辑、查看
      dialogwarningObjectVisible: false, // 部门 弹框显示隐藏
      loadingwarningObjectDialog: false, //部门 弹框loading
      listObjectLoading: false,
      tableObjectData: [],
      department_config: {
        imgKeyWord: "url",
        fileKeyWord: "url",
        fileName: "fFileName",

        dialogHeight: "",
        thead: [
          {
            label: "对象名称",
            prop: "fObjectname",
            minWidth: "100px",
            routerPath: "xxx",
            align: "center",
          },
          {
            label: "是否业主",
            prop: "fIsowner",
            minWidth: "70px",
            routerPath: "xxx",
            align: "center",
            filter: true,
            callback: (rowData) => {
              let data = objectType[rowData.fIsowner];
              if (data) {
                return data.label;
              }
            },

            // callback: (rowData) => {
            //     let data = sexType[rowData.sex]
            //     if (data) {
            //         return data.label
            //     }
            // }
          },
          {
            label: "对象类型",
            prop: "fType",
            minWidth: "100px",
            routerPath: "xxx",
            align: "center",
          },
          {
            label: "消息类型",
            prop: "fMessagetype",
            minWidth: "100px",
            routerPath: "xxx",
            align: "center",
            filter: true,
            callback: (rowData) => {
              console.log(rowData);
              let data = messageType[rowData.fMessagetype];
              if (data) {
                return data.label;
              }
            },
          },
        ],
      },
      warningObjectformData: {
        fCompanyid: "", // 施工标段id
        fId: "", // 为null或空字符串时-新增  有值-修改
        fObjectname: "", // 对象名称
        fIsowner: false, // 是否业主
        fType: "", // 类型
        fMessagetype: "", // 消息类型
        userName: this.$store.state.userInfo.realName, // 当前登陆人名称
        userId: this.$store.state.userInfo.userId, // 当前登陆人id
      }, //部门 新增编辑向后台传递对象
      warningObjectformObj: [
        //新增编辑配置参数

        {
          switch: true,
          label: "是否业主",
          prop: "fIsowner",
          placeholder: "请选择",
          width: 12, //参考el-col
          disabled: false,
        },

        {
          input: true, //是input
          label: "对象名称",
          prop: "fObjectname",
          width: 24, //参考el-col
          disabled: false,
          rules: [
            {
              required: true,
              message: "对象名称不能为空",
            },
          ], //验证
        },
        {
          select: true,
          label: "类型",
          prop: "fType",
          placeholder: "请选择",
          width: 24, //参考el-col
          disabled: false,
          options: [
            {
              label: "业主",
              value: "业主",
            },
            {
              label: "施工单位",
              value: "施工单位",
            },
            {
              label: "监理单位",
              value: "监理单位",
            },
            {
              label: "工地试验室",
              value: "工地试验室",
            },
            {
              label: "拌和站",
              value: "拌和站",
            },
          ],
        },
        {
          //新增编辑配置参数
          radio: true,
          label: "消息类型",
          prop: "fMessagetype",
          placeholder: "请选择",
          width: 24, //参考el-col
          disabled: false,
          options: [
            {
              label: "短信",
              value: "1",
            },
            {
              label: "微信公众号",
              value: "2",
            },
            {
              label: "短信和微信公众号",
              value: "3",
            },
          ],
          rules: [
            {
              required: true,
              message: "请选择消息类型",
            },
          ], //验证
        },
      ],

      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      checked: true, //查看下级
      showName: "未选择公司",
      dialogHeight: "330px", //新增编辑弹框高度
      fId: null, //点击当前列表数据fId

      // 列表给后端传参
      getList: {
        fCompanyid: "", // 施工标段id
        keyWord: "", // 模糊查询条件
        page: 1, // 当前页码
        pageSize: 20, // 每页显示条数
      },

      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据
      tableData: [], //表格列表数据列表
      // 左侧机构树
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      treeText: {
        //树状图参数
        companyId: null,
        userId: null,
      },
      checkData: [],
      fNature: "", //点击组织机构等级
    };
  },
  components: {
    tree, //左侧组织机构数
    TableData, //主页面列表
    elBreadcrumb, //面包屑
    publicForm, //弹框表格
  },
  mounted() {
    if (JSON.parse(sessionStorage.getItem("currencyList"))) {
      var id = JSON.parse(sessionStorage.getItem("currencyList"));
      this.checkData = [id.fCompanyid];
    }
    this.getTree();
    this.btnRole(this.name);
  },
  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });

        this.yj_add = btnStr.includes("yj_add");
        this.yj_edit = btnStr.includes("yj_edit");
        this.yj_view = btnStr.includes("yj_view");
      } else {
        this.yj_add = true;
        this.yj_edit = true;
        this.yj_view = true;
      }
    },

    // 点击列表当前行，获取当前信息 人员
    rowChange(row) {
      this.fId = row.fId;
    },
    // 点击列表当前行，获取当前信息 部门
    rowObjectChange(row) {
      this.warningObjectformData.fId = row.fId;
    },
    // 左侧树结构
    getTree() {
      this.treeText.companyId = this.$store.state.userInfo.companyId;
      this.treeText.userId = this.$store.state.userInfo.userId;
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);

            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
            } else {
              this.treelength = true;
            }

            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("currencyList")
              ).fShortname;

              // this.getList.companyId = this.checkData[0];
            } else {
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              // this.getList.companyId = this.treeData[0].fCompanyid; //当前点击组织机构ID
            }
            // this.showName = this.treeData[0].fShortname;//当前点击组织机构名称

            // this.getList.fCompanyid = this.treeData[0].fCompanyid;//当前点击组织机构ID
            // this.warningObjectformData.fCompanyid = this.treeData[0].fCompanyid;

            // this.yj_searchForm(this.getList);// 调用主页面列表接口
            // this.yj_ObjectForm(this.warningObjectformData.fCompanyid)
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },

    // 点击左侧机构树
    handleNodeClick(data) {
      console.log(data);
      this.showName = data.fShortname; //顶部显示机构名
      this.warningObjectformData.fCompanyid = data.fCompanyid;

      this.fNature = data.fNature;
      if (data.fNature == "施工单位") {
        this.getList.fCompanyid = data.fCompanyid; //当前点击组织机构ID
        this.yj_searchForm(this.getList);
        this.yj_ObjectForm(this.warningObjectformData.fCompanyid);
      }
    },
    tranListToTreeDatas(data) {
      //处理主页面列表树结构
      let result = [];
      if (!Array.isArray(data)) {
        return result;
      }
      // 清除已存在的数据  重新赋值
      data.forEach((item) => {
        delete item.children;
      });
      let map = {};
      data.forEach((item) => {
        map[item.fMachineid] = item;
      });
      data.forEach((item) => {
        let parent = map[item.fStationid];
        if (parent) {
          (parent.children || (parent.children = [])).push(item);
        } else {
          result.push(item);
        }
      });
      return result;
    },
    selectObjectChange(value) {
      this.warningObjectformData.fType = value.value; // 拌合站id
    },
    // 预警通知-对象列表页
    yj_ObjectForm(id) {
      this.listObjectLoading = true;
      var data = {
        fCompanyid: id,
      };
      getNoticeObjectListByCompanyId(data)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.listObjectLoading = false;
            that.tableObjectData = res.data;

            this.ObjectsData = [];
            this.ObjectsData = res.data.filter((item) => {
              if (item.fIsowner == 0) {
                return item;
              }
            });

            //
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 新增对象 部门
    yj_editObjectForm(status) {
      //0新增，1编辑

      if (status == 1) {
        this.warningObjectformData.fObjectname = "";
        this.warningObjectformData.fIsowner = false;
        this.warningObjectformData.fType = "";
        this.warningObjectformData.fMessagetype = "";

        this.submitFlag = true; //显示保存按钮
        this.warningObjectDialog = "编辑功能";
        if (
          this.warningObjectformData.fId != null &&
          this.warningObjectformData.fId != ""
        ) {
          this.dialogwarningObjectVisible = true;
          getNoticeObject({ fId: this.warningObjectformData.fId })
            .then((res) => {
              if (res.errcode == 0) {
                this.warningObjectformData = res.data;
                if (res.data.fIsowner == 0) {
                  this.warningObjectformData.fIsowner = false;
                } else if (res.data.fIsowner == 1) {
                  this.warningObjectformData.fIsowner = true;
                }
              } else {
                this.$message.error(res.msg);
                console.log("接口报错");
              }
            })
            .catch((error) => {
              console.log("拌合站设置编辑报错", error);
            });
        } else {
          return this.$message.error("请选择需要编辑的数据");
        }
      } else if (status == 0) {
        // fNature
        // if (this.getList.fCompanyid != "" && this.getList.fCompanyid != null) {
        if (this.fNature == "施工单位") {
          this.submitFlag = true; //显示保存按钮
          this.warningObjectDialog = "新增";
          this.dialogwarningObjectVisible = true;
          this.loadingwarningObjectDialog = false;

          this.warningObjectformData = {
            fCompanyid: this.getList.fCompanyid, // 施工标段id
            fId: "", // 为null或空字符串时-新增  有值-修改
            fObjectname: "", // 对象名称
            fIsowner: false, // 是否业主
            fType: "", // 类型
            fMessagetype: "", // 消息类型
            userName: this.$store.state.userInfo.realName, // 当前登陆人名称
            userId: this.$store.state.userInfo.userId, // 当前登陆人id
          };
        } else {
          return this.$message.error("请先选择施工单位");
        }
      }
    },
    // 部门保存
    yj_saveObjectForm() {
      if (this.warningObjectformData.fIsowner == false) {
        this.warningObjectformData.fIsowner = "0";
      } else if (this.warningObjectformData.fIsowner == true) {
        this.warningObjectformData.fIsowner = "1";
      }
      if (this.$refs.ObjectForm.submitForm()) {
        addNoticeObject(this.warningObjectformData)
          .then((res) => {
            if (res.errcode == 0) {
              this.yj_ObjectForm(this.warningObjectformData.fCompanyid);
              this.dialogwarningObjectVisible = false;
              this.$message.success("新增成功");
            } else {
              this.$message.error(res.msg);
              console.log("接口报错");
            }
          })
          .catch((error) => {
            console.log("拌合站设置-新增）", error);
          });
      } else {
        console.log("error");
      }
    },
    // 删除
    yj_delObjectForm(id) {
      if (id != "" && id != null) {
        this.listObjectLoading = true;
        this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            deleteNoticeObject({ fId: id }).then((res) => {
              if (res.errcode == 0) {
                this.listObjectLoading = false;
                this.yj_ObjectForm(this.warningObjectformData.fCompanyid);
                this.$message.success("删除成功");
              } else {
                this.$message.error(res.msg);
                return false;
              }
            });
          })
          .catch(() => {
            this.$message("已取消删除");
          });
      } else {
        return this.$message.error("请先选择需要删除的数据");
      }
    },
    // 是否为业主 决定所属对象数据
    IsownerChange(e) {
      this.fEquipmentname = [];
      this.ObjectsData = [];
      if (e == true) {
        this.ObjectsData = this.tableObjectData.filter((item) => {
          if (item.fIsowner == 1) {
            return item;
          }
        });
      } else if (e == false) {
        this.ObjectsData = this.tableObjectData.filter((item) => {
          if (item.fIsowner == 0) {
            return item;
          }
        });
      }
      console.log(this.ObjectsData);
    },
    // 所属对象数据
    selectEquipmen() {
      console.log(this.fEquipmentname);
      var arr = [];
      this.fEquipmentname.map((item) => {
        arr.push(item.fId);
        // this.fObjects+=item
      });
      // fId

      this.formData.fObjects = arr.join(",");
    },
    // 获取列表数据人
    yj_searchForm(data) {
      this.listLoading = true;
      getNoticeUserListsByCompanyId(data)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.listLoading = false;

            that.tableData = res.data.pageInfo.list;
            this.queryCriteriaData1 = res.data.pageInfo; //分页信息
            this.navigatepageNums1 =
              this.queryCriteriaData1.navigatepageNums.length;
            // that.tableData = that.tranListToTreeDatas(res.data.pageInfo.list)
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          this.$message.error(error.msg);
        });
    },
    // 新增、编辑
    yj_editForm(status) {
      //0新增，1编辑
      this.fEquipmentname = [];
      if (status == 1) {
        this.submitFlag = true; //显示保存按钮
        this.editDialog = "编辑功能";
        this.formData.fName = "";
        this.formData.fNumber = "";
        this.formData.fGender = "男";
        this.formData.fIsreceivetextmsg = "是";
        this.formData.fPosition = "";
        this.formData.fEducation = "";
        this.formData.fObjects = "";

        if (this.fId != null && this.fId != "") {
          this.dialogEditVisible = true;
          getNoticeUser({ fId: this.fId })
            .then((res) => {
              if (res.errcode == 0) {
                this.formData = res.data;
                if (res.data.fIsowner == 0) {
                  this.formData.fIsowner = false;
                } else if (res.data.fIsowner == 1) {
                  this.formData.fIsowner = true;
                }

                this.ObjectsData = [];
                if (this.formData.fIsowner == 1) {
                  this.ObjectsData = this.tableObjectData.filter((item) => {
                    if (item.fIsowner == 1) {
                      return item;
                    }
                  });
                } else if (this.formData.fIsowner == 0) {
                  this.ObjectsData = this.tableObjectData.filter((item) => {
                    if (item.fIsowner == 0) {
                      return item;
                    }
                  });
                }
                var getNoticeUser = res.data.fObjects.split(",");
                this.fEquipmentname = [];
                this.ObjectsData.map((i) => {
                  //筛选符合条件的所属对象
                  getNoticeUser.map((item) => {
                    if (i.fId == item) {
                      this.fEquipmentname.push(i);
                    }
                  });
                });
              } else {
                this.$message.error(res.msg);
                console.log("接口报错");
              }
            })
            .catch((error) => {
              console.log("预警通知-人员详情编辑报错", error);
            });
        } else {
          return this.$message.error("请选择需要编辑的数据");
        }
      } else if (status == 0) {
        this.submitFlag = true; //显示保存按钮
        // if (this.getList.fCompanyid != "" && this.getList.fCompanyid != null) {
        if (this.fNature == "施工单位") {
          this.editDialog = "新增";
          this.dialogEditVisible = true;
          this.loadingEditDialog = false;
          this.formData = {
            fCompanyid: this.getList.fCompanyid, // 施工单位id
            fId: "", // 为null或空字符串时-新增  有值-修改
            fIsowner: false, //是否业主
            fName: "", // 姓名
            fNumber: "", // 编号
            fTelnumber: "", // 电话
            fGender: "男", // 性别
            fIsreceivetextmsg: "是", // 是否接收短信
            fPosition: "", // 职位
            fEducation: "", // 学历
            fObjects: "1,2,3", // 对象集合
            userName: this.$store.state.userInfo.realName, // 当前登陆人名称
            userId: this.$store.state.userInfo.userId, // 当前登陆人id
          };
        } else {
          return this.$message.error("请先选择施工单位");
        }
      }
    },
    // 保存接口
    yj_saveForm() {
      // if (this.$refs.publicForm.submitForm()) {
      if (this.formData.fIsowner == false) {
        this.formData.fIsowner = "0";
      } else if (this.formData.fIsowner == true) {
        this.formData.fIsowner = "1";
      }
      console.log(this.formData);
      this.$refs.publicForm.validate((valid) => {
        if (valid) {
          // 预警通知-人员新增

          addNoticeUser(this.formData)
            .then((res) => {
              if (res.errcode == 0) {
                this.yj_searchForm(this.getList);

                this.dialogEditVisible = false;
                this.$message.success("新增成功");
              } else {
                this.$message.error(res.msg);
                console.log("接口报错");
              }
            })
            .catch((error) => {
              console.log("预警通知-人员新增", error);
            });
        } else {
          this.$message.error("请填写必填项");
          return false;
        }
      });
    },
    // 删除
    yj_delForm(id) {
      console.log(id);
      if (id != "" && id != null) {
        this.listLoading = true;
        this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            updateNoticeUser({ fId: id }).then((res) => {
              if (res.errcode == 0) {
                this.listLoading = false;
                this.yj_searchForm(this.getList);
                this.$message.success("删除成功");
              } else {
                this.$message.error(res.msg);
                return false;
              }
            });
          })
          .catch(() => {
           this.$message("取消删除");
          });
      } else {
        return this.$message.error("请先选择需要删除的数据");
      }
      //
    },
    // 多选方法
    selectionChange() { },
    // 排序方法
    sortChange() { },
  },
};
</script>
  
<style scoped lang="less">
.warningObject_table {
  display: flex;
  height: 100%;

  .perpsonObject {
    width: 70%;
    height: 100%;
    margin-right: 5px;
    // background: red;
  }

  .departmentObject {
    width: 30%;
    height: 100%;
    // background: pink;
  }
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;

  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}

#smallDialog /deep/.el-dialog {
  width: 700px !important;
}
</style>